package com.pata.display
{
	import com.pata.enum.InvalidationType;
	
	import flash.text.TextField;
	import flash.text.TextFormat;

	/**
	 * @data	2011-4-6	
	 * @author	pata
	 */
	public class Label extends AbstractDisplay implements IDisplay
	{
		
		private var mTextField:TextField;		
		private var mColor:uint;
		private var mText:String;
		private var mTextFormat:TextFormat = new TextFormat;
		
		public function get text():String
		{
			return mText;
		}
		
		public function set text(value:String):void
		{
			if(mText === value) return;
			mText = value;
			this.invalidate( InvalidationType.DATA );
		}
		
		public function get size():int
		{
			return int(mTextFormat.size);
		}
		public function set size(value:int):void
		{
			if(mTextFormat.size === value) return;
			mTextFormat.size = value;
			this.invalidate( InvalidationType.STYLES );
		}
		
		public function get fontName():String
		{
			return mTextFormat.font;
		}
		
		public function set fontName(value:String):void
		{
			if(mTextFormat.font === value) return;
			mTextFormat.font = value;
			this.invalidate( InvalidationType.STYLES );
		}
		
		public function get color():uint
		{
			return int(mTextFormat.color);
		}
		
		public function set color(value:uint):void
		{
			if(mTextFormat.color === value) return;
			mTextFormat.color = value;
			this.invalidate( InvalidationType.STYLES );
		}
		public function Label()
		{
			super( this );			
		}
		override protected function configUI():void
		{
			mTextField = new TextField;
			this.addChild(mTextField);
			mTextField.selectable = false;
			mTextField.autoSize = "left";
			mouseEnabled = false;
		}
		override public function draw():void
		{			
			if(this.mTextField)
			{				
				if(isInvalid( InvalidationType.DATA ))
				{
					mTextField.text = mText;
				}
				if(isInvalid( InvalidationType.STYLES) )
				{
					/**
					 * 在给text复制之后，才能设置textFormat，不然无效.
					 */
					mTextField.setTextFormat(mTextFormat);
				}
			}
			super.draw();
		}
	}
}